var UserData = require('./UserData')

window.ck = {
	
	getGameScene(){
		return cc.find('Canvas').getComponent('GameScene')
	},

	setPositionX(node, x) {
		node.position = new cc.Vec2(x, node.position.y)
	},

	setPositionY(node, y) {
		node.position = new cc.Vec2(node.position.x, y)
	},

	setScaleX(node, x) {
		node.scale = new cc.Vec2(x, node.scale.y)
	},

	setScaleY(node, y) {
		node.scale = new cc.Vec2(node.scale.x, y)
	},

	log() {
		
		var args = []
		args.push(`frame=${cc.director.getTotalFrames()} `)
		for(var i=0; i<arguments.length; ++i)
		{
			if (arguments[i]===null) {
				args.push("null");
			}
			else if (arguments[i]===undefined) {
				args.push("undefined");
			}
			else{
				args.push(arguments[i].toString())
			}
		}

		cc.log.apply(null, args)
		
	},

	world(node){
		return node.convertToWorldSpaceAR(new cc.Vec2(0,0))
	},

	delayCall(node, delaySecond, callback){
		cc.tween(node)
        .delay(delaySecond)
        .call(callback)
        .start()
	},

	localToLocalSpace(node1, node2, local_pos1){
		if (!local_pos1) {
			local_pos1 = new cc.Vec2(0,0)
		}
		var world = node1.convertToWorldSpaceAR(local_pos1)
		var local = node2.convertToNodeSpaceAR(world)
		return local
	},

	GameState: {
		Prepare: 'Prepare',
		Gaming: 'Gaming',
		FindDoor: 'FindDoor', //吃完所有金币
		TouchDoor: "TouchDoor", //player碰到了door，门在下落
		Finished: 'Finished', //门下落完成时触发，等待显示结束面板
		Dead: 'Dead', //角色死亡
	},

	PlayerDirection: {
		Left: 'Left',
		Right: 'Right',
		Up: 'Up',
		Down: 'Down',
	},

	Event: {
		GameStateChanged: "GameStateChanged",
	},

	userData: new UserData()
}

